<template>
  <div>
    <ZgButton icon="search" @click="selectFlow" type="link">选择流程</ZgButton>
    <ZgDialog title="选择流程" width="80%" :showFooter="false" v-model="visible">
      <ZgNewPage
        ref="page"
        :pageOpt="{ showPageTitle: false }"
        :extraHeight="400"
        :conditions="conditions"
        :dataBtns="dataBtns"
        :adminWidth="120"
        @condition="condition"
        @search="onSearch"
        @admin="toAdmin"
      >
        <template slot="columns">
          <a-table-column title="流程名称">
            <template slot-scope="record">
              {{ record.name }}
            </template>
          </a-table-column>
          <a-table-column title="流程编码">
            <template slot-scope="record">
              {{ record.code }}
            </template>
          </a-table-column>
          <a-table-column title="流程类型">
            <template slot-scope="record">
              {{ record.type }}
            </template>
          </a-table-column>
        </template>
      </ZgNewPage>
    </ZgDialog>
  </div>
</template>
<script>
export default {
  data () {
    return {
      visible: false,
      conditions: [
        { code: 'name', compType: '单行文本', label: '流程名称', defaultVal: '' },
        { code: 'code', compType: '单行文本', label: '流程code', defaultVal: '' }
        // {
        //   code: 'type',
        //   compType: '下拉选择',
        //   label: '类型',
        //   defaultVal: '',
        //   extra: {
        //     下拉选项: [
        //       { value: '1', label: '字符串' },
        //       { value: '2', label: '浮点数' }
        //     ]
        //   }
        // }
        // { code: 'age', compType: '整数', label: '年龄', defaultVal: 0 },
        // { code: 'political', compType: '字典', label: '政治面貌', defaultVal: '', extra: { 字典类型: 'political' } }
        // { code: 'is_use', compType: '布尔', label: '启用', defaultVal: 'false' }
        // { code: 'birth', compType: '日期区间', label: '生日', defaultVal: ['', ''] },
        // { code: 'age', compType: '整数区间', label: '年龄', defaultVal: [0, 100] },
        // { code: 'birth1', compType: '日期', label: '生日1', defaultVal: '2025-05-23' },
      ],
      dataBtns: [
        {
          key: 1,
          type: 'primary',
          name: '选择流程',
          icon: 'fa-check',
          isShow: () => {
            return true
          }
        }
      ]
    }
  },
  methods: {
    onSearch (param) {
      this.condition(param)
    },
    selectFlow () {
      this.visible = true
    },
    condition (param) {
      this.$http.post('/zg-autoflow/autoFlow/main/page', param, (res) => {
        this.$refs.page.endSearch({
          total: Number(res.total),
          list: res.records
        })
      })
    },
    toAdmin (param) {
      if (param.key === 1) {
        this.visible = false
        console.log(param, 'param')
        this.$emit('change', param.obj)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
